Skip to content

Conversation

@n2h9
Copy link
Contributor

@n2h9 n2h9 commented Apr 12, 2025

Description

This PR implements integration test running in ci.

Infrastructure set up was copied from meshery: link.

Test flow is as follows:

  • create kind cluster;
  • install CRDS (from meshsery repo master branch);
  • apply meshsync from hardcoded yaml (required as meshsync code is bounded to read from meshsync crd config)
  • up docker compose with nats;
  • subscribed to meshsync topic;
  • run meshsync main();
  • validate that messages were received from nats;

TODO

  • Implement more reasonable assertions;

Meshsync CI pipeline failure is fixed in a separate pr: #397

Signed commits

  • Yes, I signed my commits.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @n2h9, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces an integration test using a GitHub workflow. It adds a Makefile target for running integration tests, a docker-compose file to spin up a NATS server, and a Go test file with an integration test that verifies connectivity to the NATS server. The integration test checks if messages are received in NATS after the main application is started with the NATS broker URL set via an environment variable.

Highlights

  • Integration Test Setup: Introduces a docker-compose.yaml file to define a NATS service for local integration testing.
  • Makefile Integration Test Target: Adds an integration-test target to the Makefile to start NATS via docker-compose, run the integration tests, and then stop NATS.
  • NATS Connectivity Test: Creates a Go test (main_test.go) that verifies the application can connect to the NATS server and receive messages.

Changelog

Click here to see the changelog
  • Makefile
    • Added integration-test target to start NATS using docker-compose, run integration tests, and stop NATS.
    • The integration test requires a k8s cluster (with installed meshsync CRD) and nats streaming.
  • docker-compose.yaml
    • Created a docker-compose file to define a NATS service for local integration testing.
    • Exposes NATS ports 4222 and 8222.
  • go.mod
    • Added github.com/stretchr/testify for assertions in the integration test.
    • Added github.com/pmezard/go-difflib as an indirect dependency.
  • main_test.go
    • Created a new test file main_test.go containing the TestWithNatsIntegration function.
    • The test verifies that the application can connect to the NATS server and receive messages.
    • The test is skipped if the RUN_INTEGRATION_TESTS environment variable is not set to true.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A test to integrate,
NATS streams, communicate,
Messages flow free,
Connectivity,
Success! We celebrate.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR introduces an integration test using a GitHub workflow. It includes changes to the Makefile, adds a docker-compose file for NATS, updates go.mod, and creates a new test file (main_test.go). The integration test checks if messages are received in NATS. Overall, the changes seem reasonable, but there are a few areas that could be improved.

Summary of Findings

  • Missing Error Handling: The integration-test target in the Makefile lacks error handling for docker compose up and docker compose down. This could lead to the test failing silently if these commands fail.
  • Hardcoded Sleep Duration: The sleep 4 command in the Makefile uses a hardcoded value. It would be better to use a variable or a more dynamic approach to ensure NATS is ready before running the tests.
  • TODO in Test: The TestWithNatsIntegration function in main_test.go contains a TODO comment indicating that the check for received messages could be more meaningful.

Merge Readiness

The changes introduce a valuable integration test. However, the missing error handling in the Makefile and the TODO in the test function should be addressed before merging. I am unable to approve this pull request, and recommend that others review and approve this code before merging.

## docker compose exposes nats on default ports to host, so they must be available
integration-test:
docker compose up -d
sleep 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The sleep 4 command uses a hardcoded value. It would be better to use a variable or a more dynamic approach to ensure NATS is ready before running the tests. Consider using docker compose ps and checking the status of the NATS container.

# Example using a loop and docker compose ps (untested):
# ready=false
# until $ready; do
#   status=$$(docker compose ps --services --filter "status=running" nats)
#   if [[ "$${status}" == "nats" ]]; then
#     ready=true
#   else
#     sleep 1
#   fi
# done
sleep 4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks gemi 🤗 , the idea is good, but the suggested snippet is not working.
I briefly tried to play a little with similar ideas, but didn't succeed 😄 , so sleep 4 is the best option for now 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good comment from Gemini. While use of sleep() is almost never desired, replacement of its use can sometimes be more trouble than it's worth.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're welcome! I understand the challenges with dynamic checks in docker compose. While sleep 4 might be the most practical option for now, keep an eye on its reliability as the environment evolves. If the tests become flaky, revisiting the dynamic check might be necessary.

@n2h9 n2h9 changed the title feature: integration test: github workflow feature: integration test: in github workflow Apr 12, 2025
@n2h9 n2h9 marked this pull request as ready for review April 12, 2025 19:18
@n2h9 n2h9 requested review from aabidsofi19 and leecalcote April 13, 2025 16:25
pull_request:
branches:
- "master"
paths:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to invert this list with that of a list of files to ignore.

@leecalcote
Copy link
Member

resolved merged conflict in go.mod

Signed-off-by: Lee Calcote <[email protected]>
@leecalcote leecalcote merged commit f04e8f8 into meshery:master Apr 18, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants